package com.basedefence;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import javax.microedition.khronos.opengles.GL10;

import com.e3roid.drawable.texture.Texture.Option;
import com.e3roid.drawable.texture.Texture;
import com.e3roid.drawable.texture.TiledTexture;

public class TextureManager
{
	private static HashMap<String, TiledTexture> texturesMap = new HashMap<String, TiledTexture>();
	
	/*
	 * Return texture. It must be loaded first.
	 */
	public static TiledTexture getTexture (String name)
	{
		return texturesMap.get(name);
	}
	
	/*
	 * Return texture. Load it, if needed.
	 */
	public static TiledTexture getTexture (String name, int width, int height, int xindex, int yindex, int border, int margin, Texture.Option option)
	{
		TiledTexture texture = getTexture(name);
		
		if (texture == null)
			texture = loadTexture(name, width, height, xindex, yindex, border, margin, option);
		
		return texture;
	}
	
	public static TiledTexture loadTexture (String name, int width, int height) {
		return loadTexture(name, width, height, 0, 0, 0, 0, Option.DEFAULT);
	}
	
	public static TiledTexture loadTexture (String name, int width, int height, int xindex, int yindex, int border) {
		return loadTexture(name, width, height, xindex, yindex, border, border, Option.DEFAULT);
	}
	
	public static TiledTexture loadTexture (String name, int width, int height, int xindex, int yindex, int border, int margin) {
		return loadTexture(name, width, height, xindex, yindex, border, margin, Option.DEFAULT);
	}
	
	public static TiledTexture loadTexture (String name, int width, int height, int xindex, int yindex, int border, Texture.Option option) 
	{
		return loadTexture(name, width, height, xindex, yindex, border, border);
	}
	
	public static TiledTexture loadTexture (String name, int width, int height, int xindex, int yindex, int border, int margin, Texture.Option option)
	{
//		TiledTexture texture = new TiledTexture(name, width, height, xindex, yindex, border, margin, null, Option.DEFAULT);
		TiledTexture texture = new TiledTexture(name, width, height, xindex, yindex, border, margin, Option.DEFAULT);
		texturesMap.put(name, texture);
		return texture;
	}
	
	public static void unloadTexture (String name)
	{
		texturesMap.remove(name);
	}
}
